package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlQuestionCalculatedOptions entities. Transaction control of the save(),
 * update() and delete() operations can directly support Spring
 * container-managed transactions or they can be augmented to handle
 * user-managed Spring transactions. Each of these methods provides additional
 * information for how to configure it for the desired type of transaction
 * control.
 * 
 * @see idv.loveloser.dao.MdlQuestionCalculatedOptions
 * @author MyEclipse Persistence Tools
 */

public class MdlQuestionCalculatedOptionsDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlQuestionCalculatedOptionsDAO.class);
	// property constants
	public static final String QUESTION = "question";
	public static final String SYNCHRONIZE = "synchronize";
	public static final String SINGLE = "single";
	public static final String SHUFFLEANSWERS = "shuffleanswers";
	public static final String CORRECTFEEDBACK = "correctfeedback";
	public static final String CORRECTFEEDBACKFORMAT = "correctfeedbackformat";
	public static final String PARTIALLYCORRECTFEEDBACK = "partiallycorrectfeedback";
	public static final String PARTIALLYCORRECTFEEDBACKFORMAT = "partiallycorrectfeedbackformat";
	public static final String INCORRECTFEEDBACK = "incorrectfeedback";
	public static final String INCORRECTFEEDBACKFORMAT = "incorrectfeedbackformat";
	public static final String ANSWERNUMBERING = "answernumbering";
	public static final String SHOWNUMCORRECT = "shownumcorrect";

	public void save(MdlQuestionCalculatedOptions transientInstance) {
		log.debug("saving MdlQuestionCalculatedOptions instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlQuestionCalculatedOptions persistentInstance) {
		log.debug("deleting MdlQuestionCalculatedOptions instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlQuestionCalculatedOptions findById(java.lang.Long id) {
		log.debug("getting MdlQuestionCalculatedOptions instance with id: "
				+ id);
		try {
			MdlQuestionCalculatedOptions instance = (MdlQuestionCalculatedOptions) getSession()
					.get("idv.loveloser.dao.MdlQuestionCalculatedOptions", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlQuestionCalculatedOptions instance) {
		log.debug("finding MdlQuestionCalculatedOptions instance by example");
		try {
			List results = getSession()
					.createCriteria(
							"idv.loveloser.dao.MdlQuestionCalculatedOptions")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlQuestionCalculatedOptions instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlQuestionCalculatedOptions as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByQuestion(Object question) {
		return findByProperty(QUESTION, question);
	}

	public List findBySynchronize(Object synchronize) {
		return findByProperty(SYNCHRONIZE, synchronize);
	}

	public List findBySingle(Object single) {
		return findByProperty(SINGLE, single);
	}

	public List findByShuffleanswers(Object shuffleanswers) {
		return findByProperty(SHUFFLEANSWERS, shuffleanswers);
	}

	public List findByCorrectfeedback(Object correctfeedback) {
		return findByProperty(CORRECTFEEDBACK, correctfeedback);
	}

	public List findByCorrectfeedbackformat(Object correctfeedbackformat) {
		return findByProperty(CORRECTFEEDBACKFORMAT, correctfeedbackformat);
	}

	public List findByPartiallycorrectfeedback(Object partiallycorrectfeedback) {
		return findByProperty(PARTIALLYCORRECTFEEDBACK,
				partiallycorrectfeedback);
	}

	public List findByPartiallycorrectfeedbackformat(
			Object partiallycorrectfeedbackformat) {
		return findByProperty(PARTIALLYCORRECTFEEDBACKFORMAT,
				partiallycorrectfeedbackformat);
	}

	public List findByIncorrectfeedback(Object incorrectfeedback) {
		return findByProperty(INCORRECTFEEDBACK, incorrectfeedback);
	}

	public List findByIncorrectfeedbackformat(Object incorrectfeedbackformat) {
		return findByProperty(INCORRECTFEEDBACKFORMAT, incorrectfeedbackformat);
	}

	public List findByAnswernumbering(Object answernumbering) {
		return findByProperty(ANSWERNUMBERING, answernumbering);
	}

	public List findByShownumcorrect(Object shownumcorrect) {
		return findByProperty(SHOWNUMCORRECT, shownumcorrect);
	}

	public List findAll() {
		log.debug("finding all MdlQuestionCalculatedOptions instances");
		try {
			String queryString = "from MdlQuestionCalculatedOptions";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlQuestionCalculatedOptions merge(
			MdlQuestionCalculatedOptions detachedInstance) {
		log.debug("merging MdlQuestionCalculatedOptions instance");
		try {
			MdlQuestionCalculatedOptions result = (MdlQuestionCalculatedOptions) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlQuestionCalculatedOptions instance) {
		log.debug("attaching dirty MdlQuestionCalculatedOptions instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlQuestionCalculatedOptions instance) {
		log.debug("attaching clean MdlQuestionCalculatedOptions instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}